Skip to content

fix: route Sentry events into a frontend-visible project and harden envelope parsing#335

Merged
butschster merged 2 commits into
masterfrom
fix/sentry-event-routing-and-display
May 13, 2026
Merged

fix: route Sentry events into a frontend-visible project and harden envelope parsing#335
butschster merged 2 commits into
masterfrom
fix/sentry-event-routing-and-display

Conversation

@butschster
Copy link
Copy Markdown
Member

What

Issue #321 — fixes the dominant Sentry breakage where exceptions appeared in the "Group by type" pane but were missing from the events list, timeline, and sidebar dot, plus several smaller server-side issues uncovered along the way.

Why

The Sentry handler stored canonical events under the Sentry project ID parsed from the DSN path (/api/123/envelope/"123"). The projects table is seeded only with default, so the frontend filtered every Sentry event out of the events list (it only renders events whose project matches the active project key) and the sidebar dot never lit up. Several adjacent SDK-compat issues fell out while tracing the bug.

How

  • Auto-register projects on ingest. EventService now takes *sql.DB; HandleIncoming runs INSERT OR IGNORE INTO projects (key, name) for any project key that isn't default. The frontend already refreshes its project list when an unknown project arrives, so events become visible immediately.
  • Honor envelope item length. The previous parser split solely on \n, which corrupts items whose payloads contain literal newlines. The new parser reads length bytes when present and falls back to newline-delimited payloads otherwise.
  • Recognise trailing slashes. Sentry PHP SDK 4.x posts to /api/{id}/envelope/; the Match predicate and detectEventType now strip a trailing slash before suffix-matching.
  • Sentry-shaped ingest response. /api/{id}/envelope/ and /api/{id}/store/ now reply with {"id":"<event_id>"}; other modules keep the legacy {"status":true} body.

Testing

Covered by automated tests:

  • internal/server/http/event_service_test.goAutoRegistersProject, DefaultProjectIsNotRewritten
  • internal/server/http/ingestion_test.goSentryResponse_ReturnsEventID, SentryResponse_TransactionOnly_ReturnsSentryShape, NonSentryResponse_KeepsLegacyShape, AutoCreatesSentryProject
  • internal/server/http/detect_test.go — trailing-slash /envelope/ and /store/ cases
  • modules/sentry/envelope_test.go — length-prefixed, multi-line, multi-item, malformed-header, length-overrun
  • modules/sentry/handler_test.goMatch trailing-slash cases, Handle_EnvelopeMultilinePayload

go test ./... -count=1 and go vet ./... clean.

@butschster butschster added type: bug Something is broken or behaves incorrectly regression Worked before, broke later labels May 12, 2026
@butschster butschster requested a review from Copilot May 12, 2026 14:26
@butschster butschster self-assigned this May 12, 2026
@butschster butschster added this to the 2.3 milestone May 12, 2026
@butschster butschster moved this to Done in Buggregator May 12, 2026
@butschster butschster linked an issue May 12, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Sentry ingestion compatibility and frontend visibility by ensuring Sentry events are associated with projects that exist in the projects table, improving envelope parsing correctness (length-prefixed items), handling /envelope/ + /store/ trailing-slash paths, and returning a Sentry-compatible ingest acknowledgement body.

Changes:

  • Auto-register non-default project keys during event ingestion so newly seen Sentry project IDs become selectable/visible in the UI.
  • Rework Sentry envelope parsing to honor item length (supporting multi-line payloads) and add coverage for malformed/edge cases.
  • Make detection/matching robust to trailing slashes and return {"id":"<event_id>"} for Sentry ingests while preserving {"status":true} for other modules.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/sentry/handler.go Accept /envelope/ and /store/ paths with trailing slashes for Sentry matching.
modules/sentry/handler_test.go Adds tests for trailing-slash matching and multiline, length-prefixed envelope payloads.
modules/sentry/envelope.go Replaces newline-only splitting with a length-aware envelope item parser.
modules/sentry/envelope_test.go Adds comprehensive tests for envelope parsing (length, multiline, multi-item, malformed headers, overruns).
internal/server/http/ingestion.go Centralizes ingestion ack responses; returns Sentry-shaped {"id":...} for Sentry events.
internal/server/http/ingestion_test.go Adds tests ensuring Sentry vs non-Sentry ingest responses and project auto-creation behavior.
internal/server/http/event_service.go Auto-registers non-default projects in DB during ingestion.
internal/server/http/event_service_test.go Adds coverage for project auto-registration and ensuring default project seed isn’t overwritten.
internal/server/http/detect.go Strips trailing slashes before Sentry path suffix detection.
internal/server/http/detect_test.go Adds trailing-slash detection tests for Sentry endpoints.
internal/server/http/api_test.go Updates NewEventService construction to pass DB handle.
internal/app/app.go Updates NewEventService construction to pass DB handle.
cmd/buggregator/main.go Updates NewEventService construction to pass DB handle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modules/sentry/envelope.go Outdated
…nvelope parsing

Sentry events arrived under the Sentry project ID parsed from the DSN
path, which was never registered as a buggregator project — the frontend
filtered them out of the events list and the sidebar dot stayed unlit.
EventService now INSERT OR IGNORE's unknown project keys on ingest, the
envelope parser honors per-item length headers (multi-line payloads),
trailing slashes on /envelope/ and /store/ are recognised, and Sentry
SDKs receive {id: event_id} on a successful ingest. Issue #321.
@butschster butschster force-pushed the fix/sentry-event-routing-and-display branch from d36df44 to 7efb3fe Compare May 13, 2026 04:23
Per Copilot review on #335: pos+ih.Length can overflow signed int when
a crafted envelope declares length close to math.MaxInt, wrapping to a
negative bound that passes the additive check and then panics when
slicing. Swap to a subtractive bound (ih.Length <= len(body)-pos) and
add a regression test that triggers the overflow path.
@butschster butschster merged commit f0b1066 into master May 13, 2026
1 check passed
@butschster butschster deleted the fix/sentry-event-routing-and-display branch May 13, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

regression Worked before, broke later type: bug Something is broken or behaves incorrectly

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

v2.0 issues

2 participants